﻿using System;

namespace HslCommunication.Core.IMessage
{
	/// <summary>
	/// Modbus-Tcp协议支持的消息解析类
	/// </summary>
	// Token: 0x02000160 RID: 352
	public class ModbusTcpMessage : INetMessage
	{
		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.ProtocolHeadBytesLength" />
		// Token: 0x170005FF RID: 1535
		// (get) Token: 0x06001D99 RID: 7577 RVA: 0x0008D1D0 File Offset: 0x0008B3D0
		public int ProtocolHeadBytesLength
		{
			get
			{
				return 8;
			}
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.GetContentLengthByHeadBytes" />
		// Token: 0x06001D9A RID: 7578 RVA: 0x0008D9BC File Offset: 0x0008BBBC
		public int GetContentLengthByHeadBytes()
		{
			byte[] headBytes = this.HeadBytes;
			int? num = (headBytes != null) ? new int?(headBytes.Length) : null;
			int protocolHeadBytesLength = this.ProtocolHeadBytesLength;
			bool flag = num.GetValueOrDefault() >= protocolHeadBytesLength & num != null;
			int result;
			if (flag)
			{
				int num2 = (int)this.HeadBytes[4] * 256 + (int)this.HeadBytes[5];
				bool flag2 = num2 == 0;
				if (flag2)
				{
					byte[] array = new byte[this.ProtocolHeadBytesLength - 1];
					for (int i = 0; i < array.Length; i++)
					{
						array[i] = this.HeadBytes[i + 1];
					}
					this.HeadBytes = array;
					result = (int)this.HeadBytes[5] * 256 + (int)this.HeadBytes[6] - 1;
				}
				else
				{
					result = num2 - 2;
				}
			}
			else
			{
				result = 0;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.CheckHeadBytesLegal(System.Byte[])" />
		// Token: 0x06001D9B RID: 7579 RVA: 0x0008DAA0 File Offset: 0x0008BCA0
		public bool CheckHeadBytesLegal(byte[] token)
		{
			bool isCheckMessageId = this.IsCheckMessageId;
			bool result;
			if (isCheckMessageId)
			{
				bool flag = this.HeadBytes == null;
				if (flag)
				{
					result = false;
				}
				else
				{
					bool flag2 = this.SendBytes[0] != this.HeadBytes[0] || this.SendBytes[1] != this.HeadBytes[1];
					result = (!flag2 && this.HeadBytes[2] == 0 && this.HeadBytes[3] == 0);
				}
			}
			else
			{
				result = true;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.GetHeadBytesIdentity" />
		// Token: 0x06001D9C RID: 7580 RVA: 0x0008DB1D File Offset: 0x0008BD1D
		public int GetHeadBytesIdentity()
		{
			return (int)this.HeadBytes[0] * 256 + (int)this.HeadBytes[1];
		}

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.HeadBytes" />
		// Token: 0x17000600 RID: 1536
		// (get) Token: 0x06001D9D RID: 7581 RVA: 0x0008DB36 File Offset: 0x0008BD36
		// (set) Token: 0x06001D9E RID: 7582 RVA: 0x0008DB3E File Offset: 0x0008BD3E
		public byte[] HeadBytes { get; set; }

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.ContentBytes" />
		// Token: 0x17000601 RID: 1537
		// (get) Token: 0x06001D9F RID: 7583 RVA: 0x0008DB47 File Offset: 0x0008BD47
		// (set) Token: 0x06001DA0 RID: 7584 RVA: 0x0008DB4F File Offset: 0x0008BD4F
		public byte[] ContentBytes { get; set; }

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.SendBytes" />
		// Token: 0x17000602 RID: 1538
		// (get) Token: 0x06001DA1 RID: 7585 RVA: 0x0008DB58 File Offset: 0x0008BD58
		// (set) Token: 0x06001DA2 RID: 7586 RVA: 0x0008DB60 File Offset: 0x0008BD60
		public byte[] SendBytes { get; set; }

		/// <summary>
		/// 获取或设置是否进行检查返回的消息ID和发送的消息ID是否一致，默认为true，也就是检查<br />
		/// Get or set whether to check whether the returned message ID is consistent with the sent message ID, the default is true, that is, check
		/// </summary>
		// Token: 0x17000603 RID: 1539
		// (get) Token: 0x06001DA3 RID: 7587 RVA: 0x0008DB69 File Offset: 0x0008BD69
		// (set) Token: 0x06001DA4 RID: 7588 RVA: 0x0008DB71 File Offset: 0x0008BD71
		public bool IsCheckMessageId { get; set; } = true;
	}
}
